package com.ruoyi.marketers.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.Registration;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.auth.form.RegisterBody;
import com.ruoyi.auth.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.marketers.domain.Apply;
import com.ruoyi.marketers.service.IApplyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商家审核Controller
 * 
 * @author ruoyi
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/apply")
public class ApplyController extends BaseController
{
    @Autowired
    private IApplyService applyService;

   /* @Autowired
    private SysLoginService sysLoginService;*/
    /**
     * 查询商家审核列表
     */
    @RequiresPermissions("marketers:apply:list")
    @GetMapping("/list")
    public TableDataInfo list(Apply apply)
    {
        startPage();
        List<Apply> list = applyService.selectApplyList(apply);
        return getDataTable(list);
    }

    /**
     * 导出商家审核列表
     */
    @RequiresPermissions("marketers:apply:export")
    @Log(title = "商家审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Apply apply)
    {
        List<Apply> list = applyService.selectApplyList(apply);
        ExcelUtil<Apply> util = new ExcelUtil<Apply>(Apply.class);
        util.exportExcel(response, list, "商家审核数据");
    }

    /**
     * 获取商家审核详细信息
     */
    //@RequiresPermissions("marketers:apply:query")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
    {
        System.out.println(applyId);
        Apply apply = applyService.selectApplyByApplyId(applyId);
        System.out.println(apply);
        return success(apply);
    }



    /**
     * 获取商家审核详细信息
     */
    @RequiresPermissions("marketers:apply:query")
    @GetMapping(value = "/merchantName/{shopUser}")
    public AjaxResult getInfoMarketers(@PathVariable("shopUser") String shopUser)
    {
        Apply apply = applyService.selectApplyByMerchantName(shopUser);
        return success(apply);
    }



    /**
     * 新增商家审核
     */
    @RequiresPermissions("marketers:apply:add")
    @Log(title = "商家审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Apply apply)
    {
        int i = applyService.insertApply(apply);
        return toAjax(i);
    }

    /**
     * 修改商家审核
     */
    @RequiresPermissions("marketers:apply:edit")
    @Log(title = "商家审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Apply apply)
    {
        System.out.println(apply);
        return toAjax(applyService.updateApply(apply));
    }

    /**
     * 删除商家审核
     */
    @RequiresPermissions("marketers:apply:remove")
    @Log(title = "商家审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds)
    {
        return toAjax(applyService.deleteApplyByApplyIds(applyIds));
    }
}
